package com.zjw.strategy.SumStrategyImpl;

import com.zjw.strategy.SumStrategy;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * 总价满减策略类
 */
@Component
public class Discount4Sum implements SumStrategy {

    //满减力度
    private String discountPrice = "10";

    @Override
    public double calSum(List<Double> prices) {
        BigDecimal sumPrice = new BigDecimal("0");
        for (Double price : prices) {
            BigDecimal bigDecimal = new BigDecimal(price.toString());
            sumPrice=sumPrice.add(bigDecimal);
        }
        BigDecimal count = sumPrice.divide(new BigDecimal("100")).setScale(0, RoundingMode.HALF_DOWN);
        return sumPrice.subtract(count.multiply(new BigDecimal(discountPrice))).doubleValue();

    }
}
